import {
	Component
} from 'react';
import {
	Tab,
	Button,
	ScrollList,
	Group,
	Boxs,
	Avatar,
	Badge,
	Popup,
	ActionSheet,
	Dialog,
	Toast,
	Scroller,
	Grid,
	ImageViewer,
} from 'saltui';
const {
	IconButton,
	ButtonGroup
} = Button;
const {
	HBox,
	Box,
	VBox
} = Boxs;

import PageController from 'pages/home';
import {
	urlPrefix,
	URLS,
	nodataIcon,
	dictMap,
	msgNoData
} from '../../../app/variables';
import PostInfo from 'components/post_info';
import Upload from 'components/upload';
import DB from '../../../app/db';
import './PageHome.less';


class ReplyComment extends Component {

	constructor(props) {
		super(props);
		window.scrollTo(0, 0);
		var context = document.getElementById("context").value;
		this.state = {
			option: [],
			urlPrev: context + '/api/m/plugin/attachment/mobile/viewImage?fid=',
		}

		//this.photoTypeSuffixArray = ['.jpg', '.JPG', '.jpeg', '.JPEG', '.png', '.PNG','bmp','BMP',''];
		this.OPERATE = [{
			name: '回复',
			code: 'comments'
		},
		{
			name: '删除',
			code: 'delete'
		}
		];
	}

	componentWillMount() {
		this.judgeOperate();
	}



	judgeOperate() {
		let option = this.generateIndependentOptions();
		if (boardStatus == '1' && checkStatus1 != '3' && !listFlag) {
			this.pushInIndependentOptions(option, 'comments');
		}
		if (this.props.isauthor == '1' || this.props.isModerator || this.props.isAuthor) {
			this.pushInIndependentOptions(option, 'delete');
		}
		this.setState({
			option: option
		});

	}

	generateIndependentOptions() {
		return new Array();
	}

	pushInIndependentOptions(options, code) {

		if (options instanceof Array) {
			let n = this.acquireOptionWithName(code);
			options.push(n);
		}
		return options;
	}

	acquireOptionWithName(n) {
		let s;
		this.OPERATE.map((item, index) => {
			if (item.code == n) {
				s = item;
				return item;
			}
		});
		return s;
	}

	acquireIndependentOptionsName(options) {
		let names = [];
		if (options && options.length > 0) {
			options.map((item, index) => {
				names.push(item.name);
			});
		}
		return names;
	}

	handleOperateClick(index) {
		let t = this;
		if (t.state.option.length == 0) {
			return;
		}
		if ((t.state.option.length == 1 && t.state.option[0].name == '删除') || t.state.option.length == 2) {
			ActionSheet.show({
				options: t.acquireIndependentOptionsName(t.state.option),
				destructiveButtonIndex: t.state.option.length - 1,
				maskClosable: true,
			}, t.clickOperateItem.bind(t, t.state.option, index));
		} else {
			ActionSheet.show({
				options: t.acquireIndependentOptionsName(t.state.option),
				maskClosable: true,
			}, t.clickOperateItem.bind(t, t.state.option, index));
		}

	}

	clickOperateItem(option, num, index) {
		if (index == -1) {
			return;
		}
		let opt = option[index];
		if (opt.code == 'delete') {
			this.showConfirm('delete', '确定要删除吗？', {
				id: this.props.id
			});
			/*var img = this.props.image;
			if(this.props.image == ""){
				  img = null;
			}
		  location.hash = 'post/comment/' + this.props.id + '/'+num+'/'+this.props.author+'/'+this.props.authorName+'/'+this.props.content+'/'+this.props.createdDate+'/'+this.props.isAnonymity+'/'+img;*/
		} else if (opt.code == 'comments') {
			num = "评论" + num + "楼...";
			location.hash = 'post/reply/' + this.props.isShowAnonymity + '/' + this.props.id + '/' + this.props.boardId + '/undefined/undefined/' + this.props.author + '/' + this.props.checkStatus + '/' + num + '/' + '3'+'/undefined/'+this.props.isShowPetname;
		}
	}

	showConfirm(optionCode, content, param) {
		Dialog.confirm({
			title: '提示',
			// locale: 'en_US',
			content: content,
			onConfirm: this.confirmDialogButton.bind(this, optionCode, param),
			onCancel: (var1) => {
				console.log('confirm cancel');
			},
		});
	}

	confirmDialogButton(optionCode, argParam) {
		let t = this;
		if (optionCode == 'delete') {
			let param = {
				ids: argParam.id
			};
			DB.ForumModuleAPI.deletePost(param).then((content) => {
				Toast.show({
					type: 'success',
					content: '删除成功',
				});
				setTimeout(function () {
					this.props.flushData();
				}, 500);
			}).catch((error) => {
				Toast.show({
					type: 'error',
					content: error.errorMsg,
				});
			});
		} else if (optionCode == 'check') {
			let param = {
				ids: argParam.id
			};
			DB.ForumModuleAPI.checkPost(param).then((content) => {
				Toast.show({
					type: 'success',
					content: '审核成功',
				});
			}).catch((error) => {
				Toast.show({
					type: 'error',
					content: error.errorMsg,
				});
			});
		}
		setTimeout(function () {
			t.props.flushData();
		}, 1500);
	}

	handleCheckClick() {
		this.showConfirm('check', '确定审核通过吗？', {
			id: this.props.id
		});
	}
	getCommentList(num) {
		var img = this.props.image;
		var createdDate = "";
		if (this.props.image == "") {
			img = null;
		}
		if (this.props.createdDate == "") {
			createdDate = null;
		} else {
			createdDate = this.props.createdDate;
		}
		//pageSkip('static/officeding/forum/dist/index.html', "#/post/comment/" + this.props.id + '/'+num+'/'+this.props.author+'/'+this.props.authorName+'/'+this.props.content+'/'+this.props.createdDate+'/'+this.props.isAnonymity+'/'+img);
		location.hash = 'post/comment/' + this.props.id + '/' + num + '/' + this.props.author + '/' + this.props.authorName + '/' + createdDate + '/' + this.props.isAnonymity + '/' + img + '/' + boardStatus + '/' + boardIsDelete;
	}

	/**
	 * 点击评论回复图标的触发事件
	 * @param  {[type]}
	 * @return {[type]}
	 */
	handleClickReplyPost(item) {
		console.log(item.id);
		// alert(item.content);
		// window.salt.router.push({
		// 	id: 'replyOtherReply',
		// 	param: {
		// 		id: item.id,
		// 		content: item.content,
		// 	}
		// }).then(() => {
		// 	alert("push param success");
		// }).catch((e) => {
		// 	alert(JSON.stringify(e));
		// 	console.log(e);
		// });
		let url = 'post/reply/' + this.props.isShowAnonymity + '/' + this.props.postId + '/' + this.props.boardId + '/undefined/' + this.props.id + '/' + this.props.author + '/' + this.props.checkStatus;
		// this.props.router.push({
		// 	path: url,
		// 	query: {
		// 		name: ' sunny'
		// 	}
		// })

		// salt.router.postMessage({
		// 	key: 'sourceReplyContent',
		// 	value: item.content
		// });
		location.hash = url;
	}

	handleClickImage(imageId) {
		console.log(imageId);
	}
	/**
	 * 生成评论的HTML
	 * 
	 * @param  {[type]}
	 * @return {[type]}
	 */
	generateHtml(item) {
		var token = document.getElementById("token").value;
		var url = this.state.urlPrev;

		var imgUrl = '';
		if (this.props.image != null && this.props.image != '') {
			imgUrl = url + item.image + '&token=' + token;
		}

		let replyUserName = item.authorName.split('<');
		let checkStatus = this.props.checkStatus;
		let photo_html1 = '';
		let photo_html2 = '';
		let photo_html3 = '';
		var createdDate = '';
		if (item.createdDate != undefined && item.createdDate != 'undefined') {
			createdDate = item.createdDate;
		}
		if (this.props.attIdJson && this.props.attIdJson.length > 0) {
			photo_html1 = this.props.attIdJson.map((item, index) => {
				if (index < 3) {// this.photoTypeSuffixArray.indexOf(item.fileExt) != -1 &&
					var imageContent = url + item.id + '&token=' + token;
					if(index == this.props.attIdJson.length -1){
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 " style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}else{
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 t-MB8" style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}
				}
			});
			photo_html2 = this.props.attIdJson.map((item, index) => {
				if (index < 6 && index >= 3) {
					var imageContent = url + item.id + '&token=' + token;
					if(index == this.props.attIdJson.length -1){
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 " style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}else{
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 t-MB8" style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}
				}
			});
			photo_html3 = this.props.attIdJson.map((item, index) => {
				if (index < 9 && index >= 6) {
					var imageContent = url + item.id + '&token=' + token;
					if(index == this.props.attIdJson.length -1){
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 " style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}else{
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 t-MB8" style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}
				}
			});
		}
		let is_moderator = false;
		if (this.props.isModerator || this.props.isauthor == 1) {
			is_moderator = true;
		}
		let comment = '';
		let number = this.props.commentsNum;
		if (this.props.commentsList && this.props.commentsList.length > 0) {
			comment = this.props.commentsList.map((item1, index) => {
				if (index == 0) {
					return (
						<HBox>
							<Box flex={1} className="t-FS14 t-LH1_4 t-MB10 t-MT16">
								<span className="t-FC9 t-FL t-ML16 t-MR6">{item1.authorName}:{item1.receiverName}</span>
								<p className=" t-PL16 t-MR14" dangerouslySetInnerHTML={{__html: item1.content.replace(/(\r\n)|(\n)/g,'</br>').replace(/(\\r\\n)|(\\n)/g,'</br>')}}></p>
							</Box>
						</HBox>
					);
				}
				if (index == 1) {
					return (
						<HBox>
							<Box flex={1} className="t-FS14 t-LH1_4 t-MB10">
								<span className="t-FC9 t-FL t-ML16 t-MR6">{item1.authorName}:{item1.receiverName}</span>
								<p className=" t-PL16 t-MR14" dangerouslySetInnerHTML={{__html: item1.content.replace(/(\r\n)|(\n)/g,'</br>').replace(/(\\r\\n)|(\\n)/g,'</br>')}}></p>
							</Box>
						</HBox>
					);
				}
			});
		}
		return (
			
				<HBox vAlign="top" className=" t-PL16 t-PT30 t-BCf">
					<Box className="t-PR16" style={{ marginTop: '-6px' }}>
						{
							(imgUrl != null && imgUrl != '') ? <Avatar src={imgUrl} size={40}  /> : <Box className="t-list-img t-WH30"> <Avatar name={replyUserName[0]} size={40} style={{ fontSize: 12 }} /> </Box>
						}
					</Box>
					<Box className="t-PR16" style={{ width: '100%' }}>
						<div onClick={this.handleOperateClick.bind(this, item.index + 1)}>
							<Box className="t-FC3 " dangerouslySetInnerHTML={{ __html: item.authorName }} ></Box>
							<HBox vAlign="center" className="t-FCddfontblue-40 t-PB10 t-FS12">
								<Box className="t-MT6">
									{createdDate}
								</Box>
							</HBox>
							<Box className="dd-message t-MR14 t-LH1_6  t-OFH"  >
								<Box dangerouslySetInnerHTML={{ __html: item.content.replace(/(\r\n)|(\n)/g,'</br>').replace(/(\\r\\n)|(\\n)/g,'</br>') }}></Box>
							</Box>
						</div>
						<div>
							{/* {
								this.props.attIdJson.length > 0 ? <HBox className="t-OFH">{photo_html1}</HBox> : ""
							}
							{
								this.props.attIdJson.length > 3 ? <HBox className="t-OFH">{photo_html2}</HBox> : ""
							}
							{
								this.props.attIdJson.length > 6 ? <HBox className="t-OFH">{photo_html3}</HBox> : ""
							} */}
							{photo_html1}
							{photo_html2}
							{photo_html3}
						</div>
						<div onClick={this.getCommentList.bind(this, item.index + 1)}>
							<Box className=" t-BCf7 t-R4 t-MB20 ">
								{comment}
								{
									number > 2 ?
										<HBox >
											<Box className="t-FCddblue t-MB16 t-MT10 t-ML16" onClick={this.getCommentList.bind(this, item.index + 1)}>
												查看全部{number}条回复
							</Box>
										</HBox>
										:
										""
								}
								<Box style={{ clear: 'both' }}></Box>
							</Box>
						</div>
					</Box>
				</HBox>
			
		);

	}
	otherFloorHtml(item) {
		var token = document.getElementById("token").value;
		var url = this.state.urlPrev;

		var imgUrl = '';
		if (this.props.image != null && this.props.image != '') {
			imgUrl = url + item.image + '&token=' + token;
		}
		var createdDate = '';
		if (item.createdDate != undefined && item.createdDate != 'undefined') {
			createdDate = item.createdDate;
		}
		let replyUserName = item.authorName.split('<');
		let checkStatus = this.props.checkStatus;
		let photo_html1 = '';
		let photo_html2 = '';
		let photo_html3 = '';
		if (this.props.attIdJson && this.props.attIdJson.length > 0) {
			photo_html1 = this.props.attIdJson.map((item, index) => {
				if (index < 3) {
					var imageContent = url + item.id + '&token=' + token;
					if(index == this.props.attIdJson.length -1){
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 " style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}else{
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 t-MB8" style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}
				}
			});
			photo_html2 = this.props.attIdJson.map((item, index) => {
				if (index < 6 && index >= 3) {
					var imageContent = url + item.id + '&token=' + token;
					if(index == this.props.attIdJson.length -1){
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 " style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}else{
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 t-MB8" style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}
				}
			});
			photo_html3 = this.props.attIdJson.map((item, index) => {
				if (index < 9 && index >= 6) {
					var imageContent = url + item.id + '&token=' + token;
					if(index == this.props.attIdJson.length -1){
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 " style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}else{
						return (
							<Box className="t-R4 t-OFH t-P2 " style={{ width: "100%" }} ><img className="t-R4 t-MB8" style={{ width: "100%",objectFit:'cover'}} src={imageContent} /></Box>
						);
					}
				}
			});
		}
		let is_moderator = false;
		if (this.props.isModerator || this.props.isauthor == 1) {
			is_moderator = true;
		}
		let comment = '';
		let number = this.props.commentsNum;
		if (this.props.commentsList && this.props.commentsList.length > 0) {
			comment = this.props.commentsList.map((item1, index) => {
				if (index == 0) {
					return (
						<HBox>
							<Box flex={1} className="t-FS14 t-LH1_4 t-MB10 t-MT16">
								<span className="t-FC9 t-FL t-ML16 t-MR6">{item1.authorName}:{item1.receiverName}</span>
								<p className=" t-PL16 t-MR14" dangerouslySetInnerHTML={{__html: item1.content.replace(/(\r\n)|(\n)/g,'</br>').replace(/(\\r\\n)|(\\n)/g,'</br>')}}></p>
							</Box>
						</HBox>
					);
				}
				if (index == 1) {
					return (
						<HBox>
							<Box flex={1} className="t-FS14 t-LH1_4 t-MB10">
								<span className="t-FC9 t-FL t-ML16 t-MR6">{item1.authorName}:{item1.receiverName}</span>
								<p className=" t-PL16 t-MR14" dangerouslySetInnerHTML={{__html: item1.content.replace(/(\r\n)|(\n)/g,'</br>').replace(/(\\r\\n)|(\\n)/g,'</br>')}}></p>
							</Box>
						</HBox>
					);
				}

			});
		}
		return (

			<HBox vAlign="top" className=" t-PL16 t-PT30 t-BCf">
				<Box className="t-PR16 " style={{ marginTop: '-6px' }}>
					{
						(imgUrl != null && imgUrl != '') ? <Avatar src={imgUrl}  size={40} /> : <Box className="t-list-img t-WH30"> <Avatar name={replyUserName[0]} size={40} style={{ fontSize: 12 }} /> </Box>
					}
				</Box>
				<Box className=" t-PR16" style={{ width: '100%' }}>
					<div onClick={this.handleOperateClick.bind(this, item.index + 1)}>
						{
							item.index + 1 == this.props.elements ?
								<Box className="t-FC3 t-PB6">{item.authorName}<span className="t-FR t-FCddfontblue-40 t-PR4">沙发</span></Box>
								:
								<Box className="t-FC3 t-PB6">{item.authorName}<span className="t-FR t-FCddfontblue-40 t-PR4">{this.props.elements - item.index}楼</span></Box>
						}

						<Box className="dd-message t-LH1_6 t-OFH t-MB6"  >
							<Box dangerouslySetInnerHTML={{ __html: item.content.replace(/(\r\n)|(\n)/g,'</br>').replace(/(\\r\\n)|(\\n)/g,'</br>') }}>
							</Box>
						</Box>
					</div>
					<div>
						{/* {
							this.props.attIdJson.length > 0 ? <HBox className="t-OFH">{photo_html1}</HBox> : ""
						}
						{
							this.props.attIdJson.length > 3 ? <HBox className="t-OFH">{photo_html2}</HBox> : ""
						}
						{
							this.props.attIdJson.length > 6 ? <HBox className="t-OFH">{photo_html3}</HBox> : ""
						} */}
						{photo_html1}
						{photo_html2}
						{photo_html3}
					</div>
					<div onClick={this.getCommentList.bind(this, item.index + 1)}>
						<Box className=" t-R4 t-MB10 t-BCf7" >
							{comment}
							{
								number > 2 ?
									<HBox >
										<Box className="t-FCddblue t-MB16 t-MT10 t-ML16" >
											查看全部{number}条回复
							  </Box>
									</HBox>
									:
									""
							}
							<Box style={{ clear: 'both' }}></Box>
						</Box>
					</div>
					<div>
						<HBox vAlign="center" className="t-FCddfontblue-40 t-PB8 t-FS12">
							<Box >
								{createdDate}
								{<span className="t-FCddfontblue-60 t-PA" style={{ right: '18' }}><i onClick={this.handleOperateClick.bind(this, item.index + 1)} className="iconfont icon-discribe t-FS14"></i></span>}
							</Box>
						</HBox>

					</div>
				</Box>
			</HBox>

		);
	}

	render() {

		return (
			<div >
				<Group>{this.props.isFloor ? this.otherFloorHtml(this.props) : this.generateHtml(this.props)}</Group>
			</div>
		);
	}

}

let boardStatus;
let boardIsDelete;
let listFlag;
let checkStatus1;
let ActionSheetButton;
export default class PageHome extends Component {

	constructor(props) {
		super(props);
		//console.log(props);
		window.scrollTo(0, 0);
		var context = document.getElementById("context").value;
		let winHeight = getScrollHigh(0, 0, 1);
		let id = props.params.id;
		let _isModerator = false;
		if (props.params.isModerator == 1) {
			_isModerator = true;
		}
		let _isAuthor = false;
		if (props.params.isAuthor == 1) {
			_isAuthor = true;
		}
		this.state = {
			winHeight: winHeight,
			onlyId: '1',
			postId: id,
			option: [],
			pagetype: props.params.isCheck,
			post: {
				post: [],
				replyCount: 0,
				isModerator: _isModerator,
				isAuthor: _isAuthor,
				checkStatus: 0,
				image: '',
				attIdJson: [],
				isShowAnonymity: 0,
				isShowPetname:0,
				isAdminRole: false,
				isEditPost: '1',
				isRePost: '1',
				isCopy: '1'
			},
			isCollection: false,
			replyArray: [],
			urlPrev: context + '/api/m/plugin/attachment/mobile/viewImage?fid=',
			dataGetted: false,
			hasError: false,
			pageSize: 10,
			currentPage: 0,
			totalElements: 1,
			loading: false,
			refreshing: false,
			isNull: false,
			noMore: false,
			isFirstShow: true,
		}


	}


	componentDidMount() {
		window.scrollTo(0, 0);
		dd.biz.navigation.setTitle({
			title: '详情',
			onSuccess: function (result) {
			},
			onFail: function () {
			}
		});
	}

	componentWillUnmount() {
		if (ActionSheetButton) {
			ActionSheetButton.close();
		}
	}

	handleClickImage(imageId) {
		console.log(imageId);
	}


	checkButtonClick() {
		this.showConfirm('check', '确定审核通过吗？', {
			id: this.state.postId
		});
	}

	editButtonClick() {
		location.hash = 'post/edit/' + this.state.postId + '/' + this.state.post.checkStatus + '/' + this.state.post.author + '/' + this.state.pagetype;
	}

	deleteButtonClick() {
		this.showConfirm('delete', '确定要删除吗？', {
			id: this.state.postId
		});
	}

	cancelButtonClick() {
		history.back();
	}

	confirmDialogButton(optionCode, argParam) {
		if (optionCode == 'delete') {
			let param = {
				ids: argParam.id
			};
			DB.ForumModuleAPI.deletePost(param).then((content) => {
				Toast.show({
					type: 'success',
					content: '删除成功',
				});
				//window.salt.router.goBack();
				history.back();
			}).catch((error) => {
				Toast.show({
					type: 'error',
					content: error.errorMsg,
				});
			});
		} else if (optionCode == 'check') {
			let param = {
				ids: argParam.id
			};
			DB.ForumModuleAPI.checkPost(param).then((content) => {
				Toast.show({
					type: 'success',
					content: '审核成功',
				});
				window.salt.router.goBack();
			}).catch((error) => {
				Toast.show({
					type: 'error',
					content: error.errorMsg,
				});
			});
		}
	}


	/**
	 * 分页获取页面数据
	 * @param  {[type]}
	 * @param  {[type]}
	 * @param  {[type]}	成功的回调函数
	 * @param  {[type]} 失败的callback
	 * @return {[type]}
	 */
	viewPost(currentPage, pageSize, successCallback, errorCallBack) {
		let param = {
			id: this.state.postId,
			pagetype: this.state.pagetype,
			checkStatus: this.props.params.checkStatus,
			page: currentPage,
			onlyId: this.state.onlyId,
			rows: pageSize,
			limit: pageSize,
			start: (currentPage - 1) * pageSize,
		};
		DB.ForumModuleAPI.viewPost(param).then((content) => {
			if (content != null) {
				boardStatus = content.post.boardStatus;
				boardIsDelete = content.post.boardIsDelete;
				checkStatus1 = content.post.checkStatus;
				listFlag = content.post.blackListFlag;
				if (content.chexkDelete != '1') {
					let page = content.page;
					let noMore = (page.totalPages > page.currentPage) ? false : true;
					this.setState({
						isNull: false,
						onlyId: '0'
					}, () => {
						successCallback(noMore, content);
					})
				} else {
					this.setState({
						isNull: true,
					});
				}
			} else {
				this.setState({
					isNull: true,
				});
			}
		}).catch((error) => {
			errorCallBack();
		});
	}

	/**
	 * ScrollList 刷新函数
	 * @return {[type]}
	 */
	onRefresh() {
		this.setState({
			refreshing: true
		});
		this.viewPost(1, this.state.pageSize, (noMore, content) => {
			// var replyList = content.page.content;
			// if(replyList == null || replyList.length == 0){
			// 	replyList = [];
			// 	replyList.push(content.post.recordId);
			// }
			this.setState({
				refreshing: false,
				isCollection: content.isCollection,
				dataGetted: true,
				replyArray: content.page.content,
				totalElements: content.page.totalElements,
				currentPage: 1,
				noMore: noMore,
				hasError: false,

			});
		}, () => {
			this.setState({
				refreshing: false,
				dataGetted: true,
				noMore: noMore,
				hasError: true,
			});
		});
		Toast.hide();
	}

	/**
	 * ScrollList 正在加载函数
	 * @return {[type]}
	 */
	onLoad() {
		this.setState({
			loading: true
		});
		const curr = this.state.currentPage;

		this.viewPost(curr + 1, this.state.pageSize, (noMore, content) => {
			this.setState({
				postId: content.post.recordId,
				isCollection: content.isCollection,
				post: content.post,
				replyArray: this.state.replyArray.concat(content.page.content),
				loading: false,
				dataGetted: true,
				currentPage: curr + 1,
				totalElements: content.page.totalElements,
				noMore: noMore,
				hasError: false,
				isFirstShow: false,
			}, () => {
				this.judgeOperate();
				//this.refs.upload.initData();
			});
		}, () => {
			this.setState({
				loading: false,
				dataGetted: true,
				noMore: noMore,
				hasError: true,
			});
		});

	}

	replyPost() {
		var content = $("#replyMessage").val();
		var entity = {
			id: "",
			postId: this.state.postId,
			author: this.state.post.author,
			boardId: this.props.boardId,
			attId: "",
			content: content,
			isAnonymity: this.state.post.isAnonymity,
		};
		let param = {
			id: this.state.postId
		}
		var level = '3';
		var receiverId = '';
		DB.ForumModuleAPI.replyPost({
			entity: JSON.stringify(entity),
			level: level,
			receiverId: receiverId,
		}).then((content) => {
			Toast.show({
				type: 'success',
				content: '回帖成功',
			});
			$("#replyMessage").val("");
			this.refs.forum_view_ref.fetchData(param);
		}).catch((error) => {
			Toast.show({
				type: 'error',
				content: error.errorMsg,
			});
		});
	}

	flushViewData() {
		let param = {
			id: this.state.postId
		}
		DB.ForumModuleAPI.queryReplyCount(param).then((content) => {
			let post = this.state.post;
			post.replyCount = content;
			this.setState({
				post
			});
		}).catch((error) => {
			errorCallBack();
		});
		this.refs.forum_view_ref.fetchData(param);
	}

	handleQuickReply() {
		
		if (this.state.post.id == undefined || this.state.post.id == "") {
			Toast.show({
				type: 'error',
				content: '操作过于频繁，请稍后进行评论!',
				onHide: function () { }
			});
			return false;
		}
		location.href = '#/post/reply/' + this.state.post.isShowAnonymity + '/' + this.state.post.id + '/' + this.state.post.boradId+'/undefined/undefined/undefined/undefined/undefined/undefined/undefined/'+this.state.post.isShowPetname;
		//location.href = '#/post/reply/' + this.state.post.isShowAnonymity + '/' + this.state.post.id + '/' + this.state.post.boradId+'/'+this.state.post.isShowPetname;
		//location.href = '#/post/reply1/' + this.state.post.isShowAnonymity +'/' + this.state.post.id+'/'+this.state.post.isShowPetname;
	}

	handleClick(e) {
		let param1 = {
			id: this.state.postId,
			isCollection: this.state.isCollection
		}
		var attInfo = {};
		var isCollection = this.state.isCollection;
		this.changeCollection(param1, isCollection);

	}

	changeCollection(param1, isCollection) {
		let param = {
			id: this.state.postId
		}
		DB.ForumModuleAPI.collectionPost(
			param1
		).then((data) => {
			if (isCollection) {
				Toast.show({
					type: 'success',
					content: '取消收藏成功',

				});
			} else {
				Toast.show({
					type: 'success',
					content: '收藏成功',
				});
			}
			this.refs.forum_view_ref.fetchData(param);
		}).catch((error) => {
			Toast.show({
				type: 'error',
				content: error.errorMsg,
			});
		});

	}

	render() {
		var token = document.getElementById("token").value;
		var url = this.state.urlPrev;
		let t = this;
		var isTop = this.state.post.isTop;
		var publishTime = '';
		if (this.state.post.publishTime != undefined && this.state.post.publishTime != 'undefined') {
			publishTime = this.state.post.publishTime.substr(5, 11);
		}
		var picUrl = "";
		let labels_html;
		if (this.state.post.labels && this.state.post.labels.length > 0) {
			labels_html = this.state.post.labels.map((item, index) => {
				var labelColor = "t-tag-" + item.color + " t-MR4";
				var labelName = item.name;
				return (<span className={labelColor}>{labelName}</span>);
			});
		}
		var photosize = 0;
		var photo_html;
		if (this.state.post.attIdJson != null && this.state.post.attIdJson.length > 0) {
			photo_html = this.state.post.attIdJson.map((item, index) => {
				picUrl = url + item.id + '&token=' + token;
				photosize++;
				return (
					<Box flex={1} className="t-OFH  t-P2" style={{ width: "100%", height: "200" }}>
						<img  className="t-R4" src={picUrl} style={{ width: "100%", height: "100%" }} />
					</Box>
				);
			});
		}

		var imgUrl = '';
		if (this.state.post.image != null && this.state.post.image != '') {
			imgUrl = url + this.state.post.image + '&token=' + token;
		}

		let authorName = this.state.post.authorName;
		if (this.state.post.isAnonymity == 1 && authorName != '匿名' && authorName != null && authorName != 'undefined' && authorName != '') {
			authorName = authorName.substring(0, authorName.indexOf('<'));
		}

		let _checkStatus = this.state.post.checkStatus;
		let heightStyle = { height: "58px" };
		if (_checkStatus == '1') {
			heightStyle.height = "45px";
		}
		var isModerator = this.state.post.isModerator;
		let checkButton = 0;
		let deleteButton = 0;
		if (isModerator) {
			checkButton = 1; deleteButton = 1;
		}
		let winHeightStyle = {
			height: this.state.winHeight
		};
		var isCopy = {};
		if (this.state.post.isCopy == '1') {
			isCopy = { userSelect: 'auto', height: this.state.winHeight };
		} else {
			isCopy = { userSelect: 'none', height: this.state.winHeight };
		}
		if (this.state.pagetype == 'myreply' && this.state.post.isAuthor) {
			var heightMax = getScrollHigh(0, 0, 0);
			winHeightStyle = {
				height: heightMax
			};
		}
		return (
			<div className="board-nav ">
				<div className={this.state.isNull ? 'dd-state-page' : 't-DN'}>
					<div className="dd-state-box">
						<VBox hAlign="center">
							<Box>
								<div>
									<img src={msgNoData} alt="" />
								</div>
							</Box>
							<Box className="t-FS14 t-MT30 t-FAC t-LH1_3 t-FCddfontblue-40">
								抱歉，该帖已被删除
		            </Box>
						</VBox>
					</div>
				</div>
				<div className={this.state.isNull ? 't-DN' : ''} style={winHeightStyle} style={isCopy}>
					{
						this.state.post.checkStatus != '1' && this.state.post.checkStatus != '0' ?
							<div>
								{
									this.state.totalElements > 0 ?
										<div className = "t-PB10">
											{
												(this.state.pagetype == 'mypost' && this.state.post.isAuthor) || (this.state.pagetype == 'myreply' && this.state.post.isAuthor) ?
													<div>
														<div>
															<ScrollList
																dataGetted={this.state.dataGetted}
																data={this.state.replyArray}
																hasError={this.state.hasError}
																refreshing={this.state.refreshing}
																loading={this.state.loading}
																onRefresh={this.onRefresh.bind(this)}
																onLoad={this.onLoad.bind(this)}
																noMore={this.state.noMore}
																noDataImage={nodataIcon}
																ref='forum_view_ref'
															>
																<PostInfo postId={this.state.postId} postView={this.state.post} pagetype={this.state.pagetype} isAuthor={this.state.post.isAuthor} />
																<div className="t-PL16 t-BCf t-PR16 t-LH2 t-PT6 t-PB6 dd-bottom-border">评论({this.state.totalElements})</div>
																<ReplyComment authorNew={this.state.post.author} flushData={this.flushViewData.bind(this)} isFloor={false} isAuthor={this.state.post.isAuthor} isModerator={this.state.post.isModerator} isShowAnonymity={this.state.post.isShowAnonymity} isShowPetname={this.state.post.isShowPetname}/>
															</ScrollList>
														</div>
													</div>
													:
													<div>

														<ScrollList
															dataGetted={this.state.dataGetted}
															data={this.state.replyArray}
															hasError={this.state.hasError}
															refreshing={this.state.refreshing}
															loading={this.state.loading}
															onRefresh={this.onRefresh.bind(this)}
															onLoad={this.onLoad.bind(this)}
															noMore={this.state.noMore}
															noDataImage={nodataIcon}
															ref='forum_view_ref'
														>
															<PostInfo postId={this.state.postId} postView={this.state.post} pagetype={this.state.pagetype} isAuthor={this.state.post.isAuthor} />
															<div className="t-PL16 t-BCf t-PR16 t-LH2 t-PT6 t-PB6 dd-bottom-border">评论({this.state.totalElements})</div>
															<ReplyComment authorNew={this.state.post.author} flushData={this.flushViewData.bind(this)} isFloor={true} isAuthor={this.state.post.isAuthor} isModerator={this.state.post.isModerator} isShowAnonymity={this.state.post.isShowAnonymity} isShowPetname={this.state.post.isShowPetname} elements={this.state.totalElements}/>
														</ScrollList>
													</div>
											}
										</div> :
										<div>
											<div>
												<PostInfo postId={this.state.postId} postView={this.state.post} pagetype={this.state.pagetype} isAuthor={this.state.post.isAuthor} />
												<Box className="t-PL16 t-PR16 t-PT14 t-PB14 t-BCf t-FAC t-FCddfontblue-60">暂无评论</Box>
												<div className={this.state.isFirstShow ? '' : 't-DN'}>
													<ScrollList
														dataGetted={this.state.dataGetted}
														data={this.state.replyArray}
														hasError={this.state.hasError}
														refreshing={this.state.refreshing}
														loading={this.state.loading}
														onRefresh={this.onRefresh.bind(this)}
														onLoad={this.onLoad.bind(this)}
														noMore={this.state.noMore}
														noDataImage={nodataIcon}
														ref='forum_view_ref'
													>
													</ScrollList>
												</div>
											</div>
										</div>
								}
								<div className={this.state.pagetype == 'myreply' && this.state.post.isAuthor ? 't-DN' : ''}>
									<div className={(_checkStatus == '2' || _checkStatus == '4') && this.state.pagetype != 'mypost' ? "apply-box t-FBH" : "t-DN"}>
										<HBox className='t-PL16 t-PR16 t-PT10 t-PB10 t-bottom-fixed t-BCf no-border'>
											<Box className={t.state.isCollection ? "t-FS16 t-FC3" : "t-DN"} style={{ width: '150', paddingLeft: '50', margin: '0 auto' }} onClick={this.handleClick.bind(this)}>
												<i className='iconfont icon-collect t-FS18 t-MR8 t-FCddfontblue-40' ></i>已收藏
					             </Box>
											<Box className={t.state.isCollection ? "t-DN" : "t-FS16 t-FC3"} style={{ width: '150', paddingLeft: '50', margin: '0 auto' }} onClick={this.handleClick.bind(this)}>
												<i className='iconfont icon-collect t-FS18 t-MR8' style={{color:'#ff9b43'}}></i>收藏
					             </Box>
											{this.state.post.isRePost == '1' && boardStatus == '1' && checkStatus1 != '3' && boardIsDelete == '0' && !listFlag ?
												<Box className="t-FS16 t-FC3" style={{ width: '150', paddingLeft: '40', margin: '0 auto' }} onClick={this.handleQuickReply.bind(this)}>
													<i className="iconfont icon-forum t-FS18 t-MR8 " style={{color:'#38acff'}}></i>评论
						            </Box>
												:
												""
											}
										</HBox>
									</div>
								</div>
							</div>
							:
							<div>
								{
									this.state.post.checkStatus == '0' ?
										<div>
											<ScrollList
												dataGetted={this.state.dataGetted}
												data={this.state.replyArray}
												hasError={this.state.hasError}
												refreshing={this.state.refreshing}
												loading={this.state.loading}
												onRefresh={this.onRefresh.bind(this)}
												onLoad={this.onLoad.bind(this)}
												noMore={this.state.noMore}
												noDataImage={nodataIcon}
												ref='forum_view_ref'
											>
											</ScrollList>
										</div>
										:
										<div>
											<PostInfo postId={this.state.postId} postView={this.state.post} pagetype={this.state.pagetype} isAuthor={this.state.post.isAuthor} />
											<div className={this.state.pagetype == "myCheck" ? "t-DN" : ""}>
												<div className="t-PL16 t-BCf t-PR16 t-LH2 t-PT6 t-PB6 dd-top-border" style={{ textAlign: 'center' }}>帖子审核中</div>
											</div>
										</div>
								}
							</div>
					}
				</div>
			</div>
		);
	}
}